package com.lc.YYGH.hosp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lc.YYGH.common.exception.YyghException;
import com.lc.YYGH.common.result.ResultStatus;
import com.lc.YYGH.hosp.mapper.HospitalSetMapper;
import com.lc.YYGH.hosp.service.HospitalSetService;
import com.lc.YYGH.model.hosp.HospitalSet;
import com.lc.YYGH.vo.order.SignInfoVo;
import org.springframework.stereotype.Service;

@Service
public class HospitalSetServiceImpl extends ServiceImpl<HospitalSetMapper, HospitalSet> implements HospitalSetService {
    @Override
    public String getSignKey(String hoscode) {
        QueryWrapper<HospitalSet> queryWrapper=new QueryWrapper<>();
        queryWrapper.select("sign_key","status").eq("hoscode",hoscode);
        HospitalSet hospitalSet=baseMapper.selectOne(queryWrapper);
        if(null==hospitalSet)
        {
            //医院未开通暂时不能访问
//            throw new YyghException(ResultStatus.HOSPITAL_OPEN);
        }
        if(hospitalSet.getStatus().
                intValue()==0)
        {
            //医院被锁定
            throw new YyghException(ResultStatus.HOSPITAL_LOCK);
        }
        return hospitalSet.getSignKey();//如果都满足条件则获取signkey
    }

    @Override
    public SignInfoVo getSignInfoVo(String hoscode) {
        QueryWrapper<HospitalSet> wrapper=new QueryWrapper<>();
        wrapper.eq("hoscode",hoscode);
        HospitalSet hospitalSet=baseMapper.selectOne(wrapper);
        if(null==hospitalSet){
            throw new YyghException(ResultStatus.FAIL);
        }
        SignInfoVo signInfoVo=new SignInfoVo();
        signInfoVo.setApiUrl(hospitalSet.getApiUrl());
        signInfoVo.setSignKey(hospitalSet.getSignKey());

        return signInfoVo;
    }
}
